package com.wl.eb.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wl.eb.mapper.EbCommentMapper;
import com.wl.eb.mapper.EbNewsMapper;
import com.wl.eb.mapper.EbProductCategoryMapper;
import com.wl.eb.mapper.EbProductMapper;
import com.wl.eb.module.EbComment;
import com.wl.eb.module.EbNews;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class IndexService {

    @Resource
    private EbProductMapper ebProductMapper;
    @Resource
    private EbNewsMapper ebNewsMapper;
    @Resource
    private EbCommentMapper ebCommentMapper;
    @Resource
    private EbProductCategoryMapper ebProductCategoryMapper;

    public Map<String, Object> index(int psize){
        System.out.println("====进入IndexService的index方法===");
        Map<String,Object>result=new HashMap<>();
        //分页查询商品数据
        Page page=new Page(psize,8);
        Page Productpage = ebProductMapper.selectPage(page, null);
        //TODO 2.分页查询新闻数据 5条数据
                page = new Page(1,5);
        Page Newspage = ebNewsMapper.selectPage(page,new QueryWrapper<EbNews>().orderByDesc("en_create_time"));
        //TODO 3.分页查询留言数据 7条数据
        page = new Page(1,7);
        Page ebCommentPage = ebCommentMapper.selectPage(page,new QueryWrapper<EbComment>().orderByDesc("ec_create_time"));

        //查询分类数据
//        List<EbProductCategory> bigs = ebProductCategoryMapper.selectBigsCategory();
//        List<EbProductCategory> smalls= ebProductCategoryMapper.selectSmallsCategory();

        result.put("Productpage",Productpage);
        result.put("Newspage",Newspage);
        result.put("ebCommentPage",ebCommentPage);
//        result.put("bigs",bigs);
//        result.put("smalls",smalls);
        return result;

    }
}
